package com.syq.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.syq.mapper.DtsCommentMapper;
import com.syq.pojo.DtsComment;
import com.syq.service.DtsCommentService;
import com.syq.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName: DtsCommentServiceImpl
 * @Description: TODO
 * @Create by: syq
 * @Date: 2022/7/28 8:18
 */
@Transactional
@Service
public class DtsCommentServiceImpl implements DtsCommentService {

    @Autowired
    private DtsCommentMapper dtsCommentMapper;


    @Override
    public Object findAll(Integer page, Integer limit, Integer userId, Integer valueId, String sort, String order) {
        Map<String,Object> map=new HashMap<>();
        IPage<DtsComment> commentIPage=dtsCommentMapper.selectPage(new Page<>(page, limit),
                new QueryWrapper<DtsComment>().
                        eq(!StringUtils.isEmpty(userId), "user_id", userId).
                        eq(!StringUtils.isEmpty(valueId), "value_id", valueId).
                        orderBy(!StringUtils.isEmpty(sort), "Asc".equalsIgnoreCase(order), sort));
        map.put("total",commentIPage.getTotal());
        map.put("items",commentIPage.getRecords());
        return ResponseUtil.ok(map);
    }

    @Override
    public Object delete(DtsComment dtsComment) {
        dtsCommentMapper.deleteById(dtsComment.getId());
        return null;
    }
}
